package host;

import homeMadeExceptions.NetworkException;
import homeMadeExceptions.NotYetImplementedException;
import homeMadeExceptions.ScatterNetException;

import java.util.Vector;

import miniworld.BluezApi;
import datatypes.BluetoothDeviceAddress;
import datatypes.Host;
import datatypes.Message;

@SuppressWarnings("unused")
public abstract class RoutingNetworkSocket extends BluezApi {
	
	public Host host = null;
	
	public RoutingNetworkSocket(Host host) {
		super(host);
		this.host = host;
	}

	//Downside Layer 
	public void invokeSendMessage(Message msg, BluetoothDeviceAddress target) {
		super.rfcomm_send(msg, target);
	}

//Methods 2 - From Routing Network API to Routing Network Socket
	
	//Downside Layer Informations
	public void getDeviceListing () {
		super.hciTool_inq();
	}
	
	
	public void enableBluetoothDevice () {
		super.hciConfig_up();
	}

	public void disableBluetoothDevice () {
		super.hciConfig_down();
	}

	public void getServerSocket () throws NetworkException{
		super.rfcomm_createSocket();
		try {
			super.rfcomm_bind_and_listen(7);
		} catch (ScatterNetException e) {
			throw new NetworkException(e.getMessage());
		}
	}
	
	public void getClientSocket () throws NetworkException {
		super.rfcomm_createSocket();
	}
//Methods 4 - From BlueZApi to Routing Network Socket

	public void onReceiveMessage(Message msg, BluetoothDeviceAddress sender) {
		if (msg.isDiscoveryMessage()){
			host.getDiscoverySocket().onReceiveMessage(msg, sender);
		}	
	}

	
	public void newRemoteHostConnected (BluetoothDeviceAddress remoteHost) throws NotYetImplementedException{
		throw new NotYetImplementedException("RoutingProtocolTemplate_New Host connected not implemeted");
	}
	
	public void  onInquiryScanAnswer (Vector<BluetoothDeviceAddress> answer) throws NotYetImplementedException {
		throw new NotYetImplementedException("On Inquiry Answer not Implemented");
	}
	//an Message could not be send to target (or it is not clear if it could be send)
	public void invokeMsgLostSignal(BluetoothDeviceAddress target, Message msg) throws NotYetImplementedException {
		throw new NotYetImplementedException("RoutingProtocolTemplate_MsgLostSignal not implemented");
	}

	public void invokeMsgAckSignal(Message msg, BluetoothDeviceAddress target) throws NotYetImplementedException {
		throw new NotYetImplementedException("RoutingProtocolTemplate_MsgLostSignal not implemented");
	}
	
	public void rfcommConnectionRequestReply (BluetoothDeviceAddress pairingPartner, boolean success)throws NotYetImplementedException{
		throw new NotYetImplementedException("RoutingProtocolTemplate_Connection Request Result not implemented");
	}
	
	//--> Timestep Notification
	public void notificationAPI () {}
	
}
